﻿/** \file
* \par Subversion URL:
* \$URL: http://planar-rendering.googlecode.com/svn/trunk/frontend/src/MatlabTarget.cs $
* \version \$Rev: 78 $
* \date    \$Date: 2009-04-20 09:47:39 +0000 (Mon, 20 Apr 2009) $
*/

using System;
using System.IO;

namespace Frontend
{
	/// <summary>
	/// Target to save fractal membership data to a big tab-separated value
	/// file for rendering in matlab.
	/// </summary>
	class MatlabTarget : Target
	{
		/// <summary>The tsv file.</summary>
		public StreamWriter matlabFile;

		/// <summary>
		/// The constructor.
		/// </summary>
		/// <param name="genInit">The associated generator.</param>
		public MatlabTarget(Generator genInit) :
			base(genInit)
		{
		}

		/// <summary>
		/// Set the file to which the data will go.
		/// </summary>
		/// <param name="matlabFileInit"></param>
		public void SetFile(StreamWriter matlabFileInit)
		{
			matlabFile = matlabFileInit;
		}

		/// <summary>
		/// Process the row data.
		/// </summary>
		public override void Write(int threadno)
		{
			for (int x = 0; x < gen.row.Length; x++)
			{
				matlabFile.Write(gen.row[threadno][x]);
				matlabFile.Write('\t');
			}
			matlabFile.Write('\n');
		}

		/// <summary>
		/// End generation.
		/// </summary>
		public override void End()
		{
			matlabFile.Dispose();
		}
	}
}
